<template>
	<Table :Config="Config"></Table>

	<div>
		<a-drawer v-model:visible="tree_visible" title="权限配置" placement="right" :footer-style="{ textAlign: 'right' }">
			<a-tree v-model:expandedKeys="expandedKeys" v-model:selectedKeys="selectedKeys"
				v-model:checkedKeys="checkedKeys" checkable :tree-data="treeData"> </a-tree>
			<template #footer>
				<a-button style="margin-right: 8px" @click="onClose">取消</a-button>
				<a-button type="primary" @click="fun_set_role">提交</a-button>
			</template>
		</a-drawer>
	</div>
</template>
<script>
var dict_IsDel = [
	{ value: 0, label: '正常' },
	{ value: 1, label: '删除' },
];

var columns = [
	{ title: '自增id', dataIndex: 'user_id', iskey: true, width: 80, hidden: false, add: false, edit: false, type: 'int' },

	{ title: '添加时间', dataIndex: 'addtime', iskey: false, width: 165, hidden: true, add: false, edit: false, type: 'datetime' },
	{ title: '添加时间戳', dataIndex: 'addtime_stamp', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'long' },
	{ title: '添加用户', dataIndex: 'add_userid', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'int' },
	{ title: '修改时间', dataIndex: 'update_lasttime', iskey: false, width: 165, hidden: true, add: false, edit: false, type: 'datetime' },
	{ title: '修改时间戳', dataIndex: 'update_lasttime_stamp', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'long' },
	{ title: '最后修改人', dataIndex: 'last_userid', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'int' },
	{ title: '是否删除', dataIndex: 'isdel', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'int' },

	{ title: '微信唯一unionid', dataIndex: 'wechat_unionid', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'string' },
	{ title: '用户名', dataIndex: 'user_name', iskey: false, width: 150, hidden: false, add: true, edit: true, type: 'string' },
	{ title: '显示名称', dataIndex: 'user_show_name', iskey: false, width: 150, hidden: false, add: true, edit: true, type: 'string' },
	{ title: '用户密码', dataIndex: 'user_password', iskey: false, width: 150, hidden: true, add: true, edit: true, type: 'string' },

	{ title: '城市', dataIndex: 'city_id', iskey: false, width: 150, hidden: false, add: true, edit: true, type: 'int' },
	{ title: '备注', dataIndex: 'user_remark', iskey: false, width: 150, hidden: false, add: true, edit: true, type: 'string' },
	{ title: '身份证', dataIndex: 'user_id_card', iskey: false, width: 165, hidden: false, add: true, edit: true, type: 'string' },

	{ title: '单点登录Token', dataIndex: 'user_token', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'string' },
	{ title: '单点登录Token到期时间', dataIndex: 'user_token_exp', iskey: false, width: 165, hidden: true, add: false, edit: false, type: 'datetime' },
	{ title: '推广码(guid或随机不重复整数)', dataIndex: 'user_promote_code', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'string' },
	{ title: '邀请码(邀请人的推广码)', dataIndex: 'user_invite_code', iskey: false, width: 150, hidden: true, add: false, edit: false, type: 'string' },
	{ title: '操作', dataIndex: 'action', hidden: false, add: false, edit: false },
	//{ title: '', dataIndex: '占位' },
];

export default {
	components: {},
	data() {
		return {
			Config: {
				getPageUrl: '/manage/SystemUser/GetListByPage',
				getUrl: '/manage/SystemUser/GetById',
				addUrl: '/manage/SystemUser/Insert',
				editUrl: '/manage/SystemUser/Update',
				delUrl: '/manage/SystemUser/DeleteById',

				columns: columns,
				page: 1,
				pageSize: 15,

				navList: [
					{ to: '/', name: '首页' },
					{ to: '/', name: '用户' },
					{ to: '', name: '用户管理' },
				],
				action: [{ name: '配置权限', funName: 'fun_Event1', type: false }],
			},
			tree_visible: false,
			checkedKeys: [],
			treeData: [],
			user_id: 0,
		};
	},
	methods: {
		async fun_Event1(record) {
			var that = this;
			that.user_id = record.user_id;
			that.tree_visible = true;
			that.treeData = [];
			var ret = await that.$http.post('/manage/SystemRole/GetListByPage', {}, that);
			ret.Data.forEach((elem, index) => {
				that.treeData.push({ title: elem.role_name, key: elem.role_id });
			});

			var userRoleIDs = await that.$http.post('/manage/SystemUserRoleLink/GetListByUserID', { ID: that.user_id }, that);
			that.checkedKeys = userRoleIDs.Data;
		},
		onClose() {
			this.tree_visible = false;
		},
		fun_set_role() {
			var that = this;
			var ret = that.$http.post('/manage/SystemUserRoleLink/BatchAdd', { user_id: that.user_id, role_ids: that.checkedKeys }, that, function (ret) {
				that.$Message["success"]({ background: true, duration: 1, content: "请求成功" });
			});

			this.tree_visible = false;
		},
	},
};
</script>
